<?php
// +----------------------------------------------------------------------
// | BhAdmin [ BhAdmin匠心打造，我们相信，每个伟大的软件都有一个伟大的故事 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020~2023 https://www.bhadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed BhAdmin并不是自由软件，未经许可不能去掉BhAdmin相关版权
// +----------------------------------------------------------------------
// | Author: BAIHU  <admin@bhadmin.cn>
// +----------------------------------------------------------------------
namespace app\admin\controller;

use app\admin\logic\LoginLogic;
use app\admin\logic\MenuLogic;
use app\admin\logic\UserLogic;
use support\Backend\BackendController;
use support\Container;
use support\Response;

class IndexController extends BackendController
{
    protected $userLogic;
    protected $loginLogic;
    protected $menuLogic;

    public function __construct()
    {
        parent::__construct();
        $this->userLogic = Container::get(UserLogic::class);
        $this->loginLogic = Container::get(LoginLogic::class);
        $this->menuLogic = Container::get(MenuLogic::class);

    }


    /**
     * 获取菜单列表
     * @return Response
     * @since 2020/11/19
     */
    public function getMenuList(): Response
    {
        return success($this->menuLogic->getPermissionList($this->userId));
    }

    /**
     * 获取用户信息
     * @since 2020/11/19
     */
    public function getUserInfo(): Response
    {
        return success($this->userLogic->getUserInfo($this->userId));
    }

    /**
     * 修改用户信息
     * @since 2020/11/19
     */
    public function updateUserInfo(): Response
    {
        return success($this->userLogic->updateUserInfo($this->userId));
    }


    /**
     * 修改密码
     * @since 2020/11/19
     */
    public function updatePwd(): Response
    {
        return success($this->userLogic->updatePwd($this->userId));
    }

    /**
     * 版本信息
     * @since 2020/11/19
     */
    public function version(): Response
    {


        $text = file_get_contents(public_path('update.md'));
        $body=<<<EOF
$text
EOF;

        return success(message([
            'version' => config('app.version'),
            'body' => $body
        ]));
    }


    /**
     * 退出
     * @since 2020/11/19
     */
    public function logout(): Response
    {
        \Tinywan\Jwt\JwtToken::clear();
        $this->loginLogic->Logout();
        return success(message());
    }

}
